package com.company.test16;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created by Administrator on 2016.9.5.
 */
public class Test1613 extends JFrame{

    public Test1613(){
        JLabel label=new Slide();
        this.add(new Slide());
    }

    public static void main(String args[]){
        JFrame frame=new Test1613();

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocationRelativeTo(null);
        frame.setTitle("幻灯片");
        frame.setSize(200,200);
        frame.setVisible(true);
    }

    class Slide extends JLabel{
        int fileNumber;

        public Slide(){
            fileNumber=0;

            Timer timer=new Timer(1000,new TimerLinst());
            timer.start();
        }

        private void changeImage(){
            ImageIcon image=new ImageIcon("src/com/company/资料/"+fileNumber+".jpg");
            this.setIcon(image);
        }

        class TimerLinst implements ActionListener{
            @Override
            public void actionPerformed(ActionEvent e) {
                if(fileNumber==3){
                    fileNumber=0;
                }
                fileNumber++;

                changeImage();
            }
        }
    }
}